/*
 * @Author: boyyang
 * @Date: 2022-01-16 11:11:23
 * @LastEditTime: 2022-01-16 13:02:39
 * @LastEditors: boyyang
 * @Description: 
 * @FilePath: \boyyang\src\components\fullScreenLoading\index.ts
 */

import { InjectionKey, inject } from 'vue'

interface ILoadingOption {
    text?: string;
}

export interface ILoadingProviderApi {
    start: (option?: ILoadingOption) => void;
    end: (option?: ILoadingOption) => void;
}

const useLoading = (): ILoadingProviderApi => {
    const api = inject(fullScreenLoadingInjectKey, null)

    if (!api) {
        throw new Error('如果你想使用loading，你需要把调用其方法的组件放在 loading-provider 内部并且使用 useLoading 去获取 API。')
    }
    return api
}


export {
    useLoading
}




export const fullScreenLoadingInjectKey: InjectionKey<ILoadingProviderApi> = Symbol('fullScreenLoadingInjectKey')